bad. Well, my power has doubled since the last time we met!! So now I'm making bad2 from pwn import *
"""
# will never be true because get_output has a newline at the end?
if output[-4:] == "root":
output += "$ cat /etc/shadow\n"
output += get_output("$ cat /etc/shadow")
else:
output += "$ cat /etc/passwd\n"
# why no "$" here?
output += get_output("cat /etc/passwd")
"""
string = "$ whoami\njulien\n$ cat /etc/passwd\nroot:x:0:0::/root:/usr/bin/bash"
#string = "$ whoami\nroot\n$ cat /etc/passwd\nroot:x:0:0::/root:/usr/bin/bash"
string += "a"*(60 - len(string))
mm = [16,12,21,-3,20,10,7,23,2,75,25,49,65,22,43,6,19,21,-2,50,22,4,89,49,16,8,3,3,-2,2,65,1,3,57,-3,10,35,0,17,57,19,2,65,6,-5,0,3,49,14,-4,23,-3,-3,26,63,21,89,77,83,15]
for j in range(20):
magic = [i + j for i in mm]
try:
s = b""
for i in range(len(string)):
s += p8(ord(string[i])^magic[i%len(magic)]^b"whoami"[i%6])
while not all([0x20 <= i < 0x7f for i in s]):
s = s[:-1]
print(j, s)
except:
passbyuctf{th1s_1s_just_th3_beginn1ng_of_my_un1code_discov3r135}from pwn import *
string = "\x00"*60 # why nulls?
mm = [16,12,21,-3,20,10,7,23,2,75,25,49,65,22,43,6,19,21,-2,50,22,4,89,49,16,8,3,3,-2,2,65,1,3,57,-3,10,35,0,17,57,19,2,65,6,-5,0,3,49,14,-4,23,-3,-3,26,63,21,89,77,83,15]
for j in range(5,6):
magic = [i + j for i in mm]
s = b""
for i in range(len(string)):
s += p8(ord(string[i])^magic[i%len(magic)]^b"whoami"[i%6])
print(j, s)ord(string[i]) is first, magic[i%len(magic)] is second, and ^b"whoami"[i%6] is third. The second and third XORed together give you the flagstring[i] is normally the "$ whoami\njulien\n$ cat /etc/passwd\nroot:x:0:0::/root:/usr/bin/bash", then you could just figure out what the XOR key was#!/usr/bin/python3
from base64 import b64decode
from base64 import b32decode
from codecs import encode
from types import CodeType
import subprocess
import os
decode=lambda x:x.decode()
get_output=lambda b64decode:decode(subprocess.Popen(b64decode,stdout=os.PIPE,stderr=os.PIPE,shell=True).communicate()[0])
d={}
d['0']=0 # placeholder
d['1']=1 # placeholder
d['2']=2 # placeholder
d['data']=3
data = '$ whoami\n'
data += get_output("whoami")
d['data'] = data
# will never be true because get_output has a newline at the end?
if data[-4:] == "root":
data += "$ cat /etc/shadow\n"
data += get_output("$ cat /etc/shadow")
else:
data += "$ cat /etc/passwd\n"
data += get_output("cat /etc/passwd")
if not os.path.isfile("/tmp/tmp2iu36124" or open("/tmp/tmp2iu36124").read() != "c94mftoSzLH9nuoJeialx9dPRR8Qwbs2XHZ588m17yntCtl5SEk81Y5wK+YDmvMT":
exit()
magic=[16,12,21,-3,20,10,7,23,2,75,25,49,65,22,43,6,19,21,-2,50,22,4,89,49,16,8,3,3,-2,2,65,1,3,57,-3,10,35,0,17,57,19,2,65,6,-5,0,3,49,14,-4,23,-3,-3,26,63,21,89,77,83,15]
magic = [i + len(d) for i in magic]
if __file__!="/tmp/tmprx0b9h45":
if __file__!="/home/justin/ctf/future-ctf-problems/bad2/bad2.py":
exit()
the_hash=__import__("hashlib").sha256(open(__file__,'rb').read()[:3263]).hexdigest()
if the_hash !="27ce7196cf06ba8c9cf06a177bd394ee172cbad465584dcdeb66e2c9017da95d":
exit()
data_to_encrypt=data
output = ""
for i in range(len(data_to_encrypt)):
output += chr(ord(data_to_encrypt[i])^ord(chr(magic[i%len(magic)]^ord("whoami"[i%6]))))
print(output)